/*固定间隔时间*/
var timerspan = undefined;
/*1分钟提交时间*/
var timerminute = undefined;
/*鼠标未移动时间*/
var timecheck = undefined;
/*30秒倒计时时间*/
var timersmall = undefined;
/*是否启动*/
var isPostback = 0;
/*正常学习策略模式 1--文档学习 2--Scorm课程学习 默认0*/
var type = 0;
/*知识类型 文件类型 总页数 学习页数*/
//knowledgeType == "DocumentKnowledge"  fileType pageSize studySize
/*已学习过的课程ID*/
var stuChpIDs = "";
/*从未完成到已完成*/
var iscurfinish = undefined;
var reZero = 0;
var myPlayer;
var curversion;
/*加载事件
 $(function () {
 if (curTitle == "1") {
 curTitle = $("#hidTitle").val();
 }
 });*/

/*
 **文档内滚动条发生变化时触发
 **_currentPage：当前页
 **_totalPages：总页数
 **创建人：姜亚正
 **日期：2013-03-31
 */
function docViewerScrollChanged(currentPage, totalPages) {
    //alert("测试中别紧张—当前页：" + currentPage + "总页数：" + totalPages);
    //只有当前滚动页数大于我的最大学习页数
    if(totalPages > 0 && currentPage > studySize) {
        studySize = currentPage;
        //       if (existsUserKnowledge == 1) {
        //            submitStudy();
        //            var leaveSize = pageSize - studySize;
        //            if (leaveSize >= 0) {
        //                $("#spanLeaveSize").html("还剩" + leaveSize + "页");
        //            }
        //        }
    }
}

/*
 **文档加载完成初始化
 **创建人：李广志
 **日期：2014-11-25 14:34:08
 **参数：numPages 总页数
 */
function docLoaded(numPages) {
    type = 1;
    TimerStartLoad();
}

/*
 **页面初始化 加载倒计时
 **创建人：李广志
 **日期：2014-5-12 10:56:25
 */
function InitFrist() {

    //文档类型和视频类型需等到文件下载加载完成才会启动,且文件类型不是图片
    //if (knowledgeType == "DocumentKnowledge") {
    //    if (fileType == "Image") {
    //        TimerStartLoad();
    //    }
    //}
    // else if (knowledgeType == "CourseKnowledge") {
    //     if (fileType != "RecordingCourse") {
    //         TimerStartLoad();
    //     }
    // }
    // else {
    //     if (knowledgeType == "VideoKnowledge") {
    //         //老的视频或者音频
    //         if (knowledgeUrl.indexOf(".flv") > -1 || knowledgeUrl.indexOf(".swf") > -1 || knowledgeUrl.indexOf(".wmv") > -1 || fileType != "Video") {
    //             TimerStartLoad();
    //         }
    //     } else {
    //         TimerStartLoad();
    //    }
    // }
}

//时间启动
function TimerStartLoad() {
    /*
     **新逻辑
     **修改人：朱浩
     **修改时间：2018-05-11
     */
    if($("#hfTipBytitle").length > 0 && $("#hfTipBytitle").val() != "") {
        CheatWarming($("#hfTipBytitle").val());
    } else {
        SyncSchedule();
        if(standardStudyHours <= 0) {
            //只同步进度（实际提交）
            completeDivShow();
        } else if(standardStudyHours > 0 && standardStudyHours < 120) {
            //同步进度，15s后提交
            var smalltime = 15;
            var msg = "";
            timersmall = setInterval(function () {
                if(smalltime >= 0) {
                    if(smalltime > 0) {
                        msg = smalltime + secondtime;
                    } else {
                        InitLoadStudy();
                    }
                    $('#spanCountdown').html(msg);
                    smalltime = smalltime - 1;
                }
                else {
                    clearInterval(timersmall);
                }
            }, 1000);
        } else {
            InitLoadStudy();
        }
    }
    //第一次学习时，10秒后自动添加用户学习
    //    if(existsUserKnowledge == 0) {
    //        var smalltime = 10;
    //        var msg = "";
    //        timersmall = setInterval(function () {
    //            if(smalltime >= 0) {
    //                if(smalltime > 0) {
    //                    msg = smalltime + "秒";
    //                } else {
    //                    //AddUserKnowledge();
    //                    SyncSchedule();
    //                    existsUserKnowledge = 1;
    //                    InitLoadStudy();
    //                    //重置学习页数为1---文档
    //                    studySize = 1;
    //                    //SpecialControl();
    //                    $('#divProcessArea').show();
    //                    $('#ScheduleText').show();
    //                    $('#divStartArea').show();
    //                    $('#divNotStartArea').hide();
    //                    $('#divWarkup').show();
    //                    $('#spantalscore').text(standardStudyScore);
    //                    if(initiativeCreditMode == 0) {
    //                        $('#spanStudyScroeShow').show();
    //                    }
    //                }
    //                $('#spanCountdown').html(msg);
    //                smalltime = smalltime - 1;
    //            }
    //            else {
    //                clearInterval(timersmall);
    //            }
    //        }, 1000);
    //    } else {
    //        if(isSingle == "1" && curTitle != "") {
    //            if(curTitle == "1") {
    //                var arr = "{}";
    //                $.ajax({
    //                    type: "POST",
    //                    contentType: "text/json",
    //                    url: "/Services/StyService.svc/GetstudyTrack",
    //                    data: arr,
    //                    dataType: 'json',
    //                    cache: false,
    //                    async: false,
    //                    success: function (result) {
    //                        CheatWarming(result);
    //                    }
    //                });
    //            }
    //        } else {
    //            //同步进度
    //            SyncSchedule();
    //            InitLoadStudy();
    //        }
    //    }
}




//自动添加用户学习信息同时发现
function AddUserKnowledge() {
    if(isSingle == "1" && curTitle != "") {
        CheatWarming(curTitle);
    } else {
        var arr = '{"orgID":"' + orgID + '","userID":"' + userID + '","knowledgeID":"' + key + '","packageID":"' + packageID + '","masterID":"' + masterID + '","masterType":"' + masterType + '","isSingle":"' + isSingle + '"}';
        $.ajax({
            type: "POST",
            contentType: "text/json",
            url: "/Services/StyService.svc/AutoCreateUserKnowledge",
            data: arr,
            dataType: 'json',
            cache: false,
            success: function (result) {
                if(result != "") {
                    CheatWarming(result);
                } else {
                    //同步进度
                    SyncSchedule();
                    existsUserKnowledge = 1;
                    InitLoadStudy();
                    //重置学习页数为1---文档
                    studySize = 1;
                    SpecialControl();
                    $('#divProcessArea').show();
                    $('#ScheduleText').show();
                    $('#divStartArea').show();
                    $('#divNotStartArea').hide();
                    $('#divWarkup').show();
                    $('#spantalscore').text(standardStudyScore);
                    if(initiativeCreditMode == 0) {
                        $('#spanStudyScroeShow').show();
                    }
                }
            }
        });
    }
}

//作弊提示
function CheatWarming(title) {
    $("#divProcessArea").hide();
    $("#ScheduleText").hide();
    $("#divNotStartArea").hide();
    $("#divCompletedArea").hide();
    $("#divStartArea").hide();
    isHere = 1;

    if(title == "-2" || title == "-2.") {
        AppendEditPlanHtml();
    } else if(title == "-1" || title == "-1.") {
        AppendFilePlanHtml();
    } else {
        title = escape2Html(title);
        if(title.length > 8) {
            title = title.substring(0, 8) + "…";
        }
        title = "[" + title + "]";
        showSingleTrack(title);
    }
}

/*
 **针对文档以及Scorm课程的特殊控制
 **创建人：李广志
 **日期：2014-5-12 10:56:25
 */
function SpecialControl() {
    //控制文档页数
    //    if (type == 1) {
    //        var leaveSize = pageSize - studySize;
    //        if (leaveSize >= 0) {
    //            $("#spanLeaveSize").html("还剩" + leaveSize + "页");
    //        }
    //    }
}

/*
 **获取学习的最新进度
 **创建人：李广志
 **日期：2014-5-12 10:56:25
 */
function GetCurSchedule() {
    //注：toFixed()返回的结果是string
    var actualSchedule = 0;
    if(actualStudyHours == standardStudyHours) {
        actualSchedule = 100;
    } else if(actualStudyHours >= validtimeSpan) {
        //实际学时小于间隔时间 不能算进度
        //本次满120提交
        actualSchedule = (parseFloat(actualStudyHours / 120) * 120 * 100 / standardStudyHours).toFixed(2);
    }
    //type在测试中发现打开的文档，但是type还是0
    //if (type > 0) {
    //if (knowledgeType == "DocumentKnowledge" || knowledgeType == "CourseKnowledge") {
    //    //如果是文档 那么就要取决于二者之间较小值
    //    var sizeSchedule = (studySize * 100 / pageSize).toFixed(2);
    //    //由于上述结果是string类型，所以要转为数字型
    //    if (parseFloat(sizeSchedule) < parseFloat(actualSchedule)) actualSchedule = sizeSchedule;
    //}
    return actualSchedule;
}

/*
 **初次加载学习
 **创建人：李广志
 **日期：2014-5-12 10:56:25
 */
function InitLoadStudy() {
    if(standardStudyHours < validtimeSpan) {
        //当前学习的知识标准学时小于间隔时间 那么立即完成
        if(fileType == "ScormCourse" && (parseFloat(curversion) == 1.2 || parseFloat(curversion) == 1.3 || parseFloat(curversion) == 2004)) {
            submitStudy();
        } else {
            completedStudy();
        }
    } else {
        /*if(standardStudyHours<=actualStudyHours){
         $('#divCheat').hide();
         $("#divProcessArea").show();
         $("#ScheduleText").show();
         $("#divNotStartArea").hide();
         $("#divCompletedArea").show();
         $("#divStartArea").hide();
         //即刻显示
         if (initiativeCreditMode == 0 && getCreditMode == 0 && standardStudyScore > 0) {
         $("#spanFinishScore").show();
         $("#spanActCmpScore").text(standardStudyScore);
         $("#spanTalCmpScore").text(standardStudyScore);
         }
         if ($('#icon' + key)) {
         $('#icon' + key).prop("class", "pic2");
         iscurfinish = 1;
         }
         actualStudyHours = standardStudyHours;
         studySize = pageSize;
         submitStudy();
         MinuteChange(100);
         isHere = 1;
         clearInterval(timer);
         clearInterval(timecheck);
         }else{*/
        //当前知识的学时小于当前间隔提交时间
        countDown(standardStudyHours - actualStudyHours, function (msg) {
            $('#spanLeavTimes').html(msg);
        });
        //当前本次学习的剩余时间大于间隔时间，那么到达指定的时间点才会真真的提交一次数据
        //否则 在本次学习到达指定的0秒之后直接提交完成
        if(standardStudyHours - actualStudyHours >= validtimeSpan) {
            UserActionTimer.fn.Start(key, validtimeSpan);
            timecheck = setInterval(CheckIsMove, validtimeSpan * 1000);
        }


        SpecialControl();
    }
}

var timer, daysold, hrsold, minsold, seconds;
//倒计时间
function countDown(maxtime, fn) {
    clearInterval(timer);
    timer = setInterval(function () {
        //将当前的页面中实际学时
        if(maxtime > 0) {
            var msg = "";
            daysold = Math.floor(maxtime / 86400);
            if(daysold > 0) {
                msg += daysold + daytime;
            }
            var e_hrsold = maxtime - (daysold * 86400);
            hrsold = Math.floor(e_hrsold / 3600);
            if(hrsold > 0) {
                msg += hrsold + hourtime;
            }
            var e_minsold = e_hrsold - (hrsold * 3600);
            minsold = Math.floor(e_minsold / 60);
            if(minsold > 0) {
                msg += minsold + minutetime;
            }
            seconds = e_minsold - (minsold * 60);
            if(seconds > 0) {
                msg += seconds + secondtime;
            }
            //actualStudyHours作为标准 由于手机端1分钟提交后，再使用PC端学习会导致一分钟就会提交
            //if (actualStudyHours >= validtimeSpan && actualStudyHours % validtimeSpan == 0 && isPostback == 1)
            if(reZero >= validtimeSpan && reZero % validtimeSpan == 0 && isPostback == 1) {
                submitStudy();
            }
            if(antionhook == "1") {
                if(reZero >= phaseTrackIntervalTime && reZero % phaseTrackIntervalTime == 0) {
                    try {
                        //显示学习提醒
                        var isScorm = document.getElementById('iframeScorm');
                        if(isScorm != null) {
                            isScorm.style.display = 'none';
                        }
                        AppendWarningHtml();
                    }
                    catch(e) { }
                }
            }
            reZero++;
            actualStudyHours++;
            isPostback = 1;
            fn(msg);
            --maxtime;
        }
        else {
            //1---表示正常通过 0---无法通过
            var isPass = 1;
            //表示时间已经走完 那么只要是文档全部学完
            if(type > 0) {
                isPass = 0;
                if(studySize >= pageSize) {
                    isPass = 1;
                }
            }
            if(isPass == 1) {
                if(initiativeCreditMode == 0 && getCreditMode == 0 && standardStudyHours > 0) {
                    $('#spanFinishScroeShow').show();
                    $("#spanFinishScore").show();
                    $("#spanActCmpScore").text(standardStudyScore);
                    $("#spanTalCmpScore").text(standardStudyScore);
                }
                submitStudy();
            } else {
                submitStudy();
                $('#spanLeavTimes').html("0" + secondtime);
            }

            clearInterval(timer);
            clearInterval(timecheck);
        }
    }, 1000);
}

//1分钟更新页面效果
function MinuteChange(actualSchedule) {
    if(actualSchedule < 100) {
        if(actualSchedule > 0) {
            //学习中
            $("#divScheduleWidth").css("width", (actualSchedule * 1.13) + "px");
            $("#ScheduleText").html(actualSchedule + "%");
            $("#hidStudySchedule").val(actualSchedule);
            $('div.select').find('.percent').html(actualSchedule + "%");
            var subcat = ((actualSchedule * standardStudyScore) / 100).toFixed(2);
            //即刻显示
            if(getCreditMode == 0) {
                //$("#spanActualScore").show();
                $("#spanobscore").text(subcat);
            }
            if(actualSchedule >= studyRate) {
                //显示立即完成
                //$("#btnComplete").show();
                $("#spanCmp").html("<input type=\"button\" class=\"btn btn-warning\" value=\"" + ifinishstudy + "\" onclick=\"completedStudy();\" />");
                $("#divHead2").show();
            }
            $('#hidUserActualStudyScore').val(subcat);
            $('#hidUserActualStudyHours').val(actualStudyHours);
        } else {
            $("#divScheduleWidth").css("width", "0px");
        }
    } else {
        //完成中
        $("#divScheduleWidth").css("width", "113px");
        $("#ScheduleText").html("100" + "%");
        $("#hidStudySchedule").val("100");
        $('div.select').find('.percent').html("100%");
        actualStudyHours = standardStudyHours;
        studySize = pageSize;
        if(initiativeCreditMode == 0 && standardStudyScore > 0) {
            $('#spanFinishScroeShow').show();
            $("#spanFinishScore").show();
            $("#spanActCmpScore").text(standardStudyScore);
            $("#spanTalCmpScore").text(standardStudyScore);
        }
    }
}

var thisU;
var UserActionTimer = function () {
    return new UserActionTimer.fn.init();
}

UserActionTimer.fn = UserActionTimer.prototype = {
    Key: undefined, //主键
    LastMouseActionTime: new Date(), //鼠标最后活动时间
    shadowTimer: undefined,
    TotalActionTime: 0, //总活动时间
    ValidTimeSpan: undefined, //有效时间间隔
    MouseActionTime: undefined, //当前鼠标活动时间
    TempTimeSpan: undefined, //临时存放时间间隔
    PostInterval: undefined,
    LastPostTotalActionTime: new Date(),
    init: function () {
        this.LastMouseActionTime = new Date();
        this.TotalActionTime = 0;
        return this;
    },
    //全屏时间事件方法
    SetValidTimeSpan: function (isFullScreen) {
        thisU = this;
        if(isFullScreen) {
            thisU.TempTimeSpan = thisU.ValidTimeSpan;
            thisU.ValidTimeSpan = 10000; //全屏默认间隔2.5小时
        }
        else {
            if(thisU.TempTimeSpan) {
                //计算全屏时间
                var timeSpan = 0; //相减的时间间隔
                thisU.MouseActionTime = new Date();
                timeSpan = thisU.MouseActionTime.getTime() - thisU.LastMouseActionTime.getTime();
                if(timeSpan <= thisU.ValidTimeSpan * 1000)
                    thisU.TotalActionTime = thisU.TotalActionTime + timeSpan;
                thisU.LastMouseActionTime = thisU.MouseActionTime;
                //设置回默认间隔时间
                thisU.ValidTimeSpan = thisU.TempTimeSpan;
                thisU.TempTimeSpan = 0;
            }
        }
    },
    Start: function (key, validtimeSpan) {
        //debugger;
        thisU = this;
        if(!key || key == "") {
            return false;
        }
        else
            this.Key = key;
        if(!validtimeSpan || validtimeSpan == "")
            this.ValidTimeSpan = 200;
        else
            this.ValidTimeSpan = validtimeSpan;
        //this.mouseActionHand(this);
        $("body").bind("click", { actionType: "click", thisUserActionTimer: this }, this.mouseActionHandler);
        $("body").bind("mousewheel", { actionType: "mousewheel", thisUserActionTimer: this }, this.mouseActionHandler);
        $("body").bind("mousemove", { actionType: "mousemove", thisUserActionTimer: this }, this.mouseActionHandler);
        $("body").bind("keydown", { actionType: "keydown", thisUserActionTimer: this }, this.mouseActionHandler);
        //$("body").bind("beforeunload", { thisUserActionTimer: this }, this.firstPostDateHandler);
        ///////////////onbeforeunload开始////////////////////
        var timeSpan = 0; //相减的时间间隔
        thisU.MouseActionTime = new Date();
        timeSpan = thisU.MouseActionTime.getTime() - thisU.LastMouseActionTime.getTime();
        /*isHere为不在学习计划完成时控制*/
        //        if(antionhook == "1") {
        //            if(timeSpan > phaseTrackIntervalTime * 1000 && timer != undefined) {
        //                try {
        //                    //显示学习提醒
        //                    var isScorm = document.getElementById('iframeScorm');
        //                    if(isScorm != null) {
        //                        isScorm.style.display = 'none';
        //                    }
        //                    //$("#dvWarningView").show();
        //                    AppendWarningHtml();
        //                }
        //                catch(e) { }
        //            }
        //        }
    },
    mouseActionHandler: function (event) {
        var thisShadow = $("#bodyShadow");
        if(thisShadow) {
            thisShadow.hide();

            if(this.shadowTimer) {
                clearTimeout(this.shadowTimer);
            }

            this.shadowTimer = setTimeout(function () {
                thisShadow.show();
            }, 15000);
        }


        thisU = event.data.thisUserActionTimer;
        var timeSpan = 0; //相减的时间间隔
        thisU.MouseActionTime = new Date();
        timeSpan = thisU.MouseActionTime.getTime() - thisU.LastMouseActionTime.getTime();
        if(timeSpan <= thisU.ValidTimeSpan * 1000)
            thisU.TotalActionTime = thisU.TotalActionTime + timeSpan;
        thisU.LastMouseActionTime = thisU.MouseActionTime;
        clearInterval(timecheck);
        timecheck = setInterval(CheckIsMove, validtimeSpan * 1000);
    },
    version: "1.0.0"
};

/*加载事件*/
function CheckIsMove() {
    UserActionTimer.fn.Start(key, validtimeSpan);
}

/*全屏状态切换事件*/
function fullScreenAction(isFullScreen) {
    UserActionTimer.fn.SetValidTimeSpan(isFullScreen);
}

//重置定时器
function ResetTimer() {
    var div = $("#divNotStartArea");
    if(!div.is(":visible")) {
        window.setTimeout(function () {
            //alert(standardStudyHours + "|" + actualStudyHours);
            isHere = 1;
            try {
                thisU.MouseActionTime = new Date();
                thisU.LastMouseActionTime = thisU.MouseActionTime;
            }
            catch(e) {
            }
            isHere = 0;
            InitLoadStudy();
        }, 1000);
    }
}

function StopTimer() {
    clearInterval(timer);
}

//提交学习
function submitStudy() {
    //进度
    var actualSchedule = GetCurSchedule();
    var viewschedule = 0;
    if($("#hidViewSchedule").length > 0) {
        viewschedule = $("#hidViewSchedule").val();
    }
    var masterTypeStr = masterType;
    if(masterType != "Plan" && masterType != "PlanStudy" && masterType != "Position" && masterType != "PositionStudy") {
        masterTypeStr = "";
    }
    var arr = '{"OrgID":"' + orgID + '","UserID":"' + userID + '","KnowledgeID":"' + key + '","PackageID":"' + packageID + '","MasterID":"' + masterID + '","MasterType":"' + masterTypeStr + '","PageSize":' + pageSize + ',"StudyTime":-1,"studyChapterIDs":"' + stuChpIDs + '","Type":' + type + ',"IsOffLine":false,"DeviceId":"","IsEnd":false,"ReqType":0,"IsCare":true,"viewSchedule":' + parseFloat(viewschedule) + '}';
    AjaxCallApiMethod({
        type: "POST",
        url: "study",
        data: arr,
        success: function (result) {
            if(result == "") {
                $('#divCheat').hide();
                //返回当前用户学习实体
                if(standardStudyHours > actualStudyHours) {
                    $("#divCompletedArea").hide();
                    if(fileType != "ScormCourse") {
                        $("#divStartArea").show();
                    }
                } else {
                    if(fileType != "ScormCourse") {
                        $("#divCompletedArea").show();
                    }
                    $("#divStartArea").hide();
                    isHere = 1;
                    if($('#icon' + key)) {
                        $('#icon' + key).prop("class", "pic2");
                        iscurfinish = 1;
                    }
                }
                MinuteChange(actualSchedule);
            } else {
                if(result.indexOf('﹡') > -1) {
                    var arrResult = result.split('﹡');
                    if(arrResult.length > 0) {
                        result = arrResult[1];
                        if(result.length > 8) {
                            result = result.substring(0, 8) + "...";
                        }
                        result = "[" + result + "]";
                    }
                }
                //那么返回的是知识名称
                CheatWarming(result);
            }
        },
        error: function (xhr) {
            var msg = eval("(" + xhr.responseText + ")");
            var result = msg.error.message;
            if(result.indexOf('﹡') > -1) {
                var arrResult = result.split('﹡');
                if(arrResult.length > 0) {
                    result = arrResult[1];
                    if(result.length > 8) {
                        result = result.substring(0, 8) + "...";
                    }
                    result = "[" + result + "]";
                }
            }
            CheatWarming(result);
        }
    });
}

//完成效果
function completeDivShow() {
    if(fileType != "ScormCourse") {
        $('#divCheat').hide();
        $("#divProcessArea").show();
        $("#ScheduleText").show();
        $("#divNotStartArea").hide();
        $("#divCompletedArea").show();
        $("#divStartArea").hide();
    }
    //即刻显示
    if(initiativeCreditMode == 0 && getCreditMode == 0 && standardStudyScore > 0) {
        $("#spanFinishScore").show();
        $("#spanActCmpScore").text(standardStudyScore);
        $("#spanTalCmpScore").text(standardStudyScore);
    }
    if($('#icon' + key)) {
        $('#icon' + key).prop("class", "pic2");
        iscurfinish = 1;
    }
    actualStudyHours = standardStudyHours;
    studySize = pageSize;
    MinuteChange(100);
    isHere = 1;
    clearInterval(timer);
    clearInterval(timecheck);
}

//提交完成(实时获取)
function completedStudy() {
    var actualSchedule = GetCurSchedule();
    var viewschedule = 0;
    if($("#hidViewSchedule").length > 0) {
        viewschedule = $("#hidViewSchedule").val();
    }
    var masterTypeStr = masterType;
    if(masterType != "Plan" && masterType != "Position") {
        masterTypeStr = "";
    }
    var arr = '{"OrgID":"' + orgID + '","UserID":"' + userID + '","KnowledgeID":"' + key + '","PackageID":"' + packageID + '","MasterID":"' + masterID + '","MasterType":"' + masterTypeStr + '","PageSize":' + pageSize + ',"StudyTime":-1,"studyChapterIDs":"' + stuChpIDs + '","Type":' + type + ',"IsOffLine":false,"DeviceId":"","IsEnd":true,"ReqType":0,"IsCare":true,"viewSchedule":' + parseFloat(viewschedule) + '}';
    AjaxCallApiMethod({
        type: "POST",
        url: "study",
        data: arr,
        success: function (result) {
            if(result == "") {
                completeDivShow();
            } else {
                if(result.indexOf('﹡') > -1) {
                    var arrResult = result.split('﹡');
                    if(arrResult.length > 0) {
                        result = arrResult[1];
                        if(result.length > 8) {
                            result = result.substring(0, 8) + "...";
                        }
                        result = "[" + result + "]";
                    }
                }
                //那么返回的是知识名称
                CheatWarming(result);
            }
        },
        error: function (xhr) {
            var msg = eval("(" + xhr.responseText + ")");
            var result = msg.error.message;
            if(result.indexOf('﹡') > -1) {
                var arrResult = result.split('﹡');
                if(arrResult.length > 0) {
                    result = arrResult[1];
                    if(result.length > 8) {
                        result = result.substring(0, 8) + "...";
                    }
                    result = "[" + result + "]";
                }
            }
            CheatWarming(result);
        }
    });
}

//将转义字符转化成普通字符
function escape2Html(str) {
    var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
    return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; });
}

//追加我在的
function AppendWarningHtml() {
    if($("#dvWarningView").length <= 0) {
        var str = "<div class='playgoon' id='dvWarningView'>" +
            "<div class='el-playgoon-shadow'></div>" +
            "<div class='playgoonbg'></div>" +
            "<div class='playgooncontent'>" + $("#hfTip").val() + "</div>" +
            "<input type='button' class='btnok' value='" + iheretitle + "' onclick='RemoveWarningHtml();' /></div>";
        if(knowledgeType == "DocumentKnowledge") {
            $("#playercontainerdiv").append(str);
        } else {
            $("#playercontainer").append(str);
        }
        if(knowledgeType == "VideoKnowledge") {
            if(typeof (myPlayer) != "undefined" && myPlayer.getState() == "playing") {
                myPlayer.pause();
            } else {
                clearInterval(timer);
            }
        } else {
            clearInterval(timer);
        }
    }
}
//删除我在的
function RemoveWarningHtml() {
    $("#dvWarningView").remove();
    //显示学习提醒
    var isScorm = document.getElementById('iframeScorm');
    if(isScorm != null) {
        isScorm.style.display = '';
    }
    if(knowledgeType == "VideoKnowledge") {
        if(typeof (myPlayer) != "undefined" && myPlayer.getState() == "paused") {
            myPlayer.play();
        } else {
            ResetTimer();
        }
    } else {
        ResetTimer();
    }
}
//追加单点跟踪
function showSingleTrack(title) {
    var isScorm = document.getElementById('iframeScorm');
    if(isScorm != null) {
        isScorm.style.display = 'none';
    }
    if($("#dvSingleTrack").length <= 0) {
        var str = "<div id='dvSingleTrack' class='playgoon'>" +
            "<div class='el-playgoon-shadow'></div>" +
            "<div class='playgoonbg'></div>" +
            "<div class='playgooncontent'>" +
            trackanticheat1 + title + trackanticheat2 +
            "</div>" +
            "<input type='button' style='width: 150px; margin-left: 175px;' onclick='StartCurStudy();' value='" + iwantstudy + "' class='btnok' />" +
            "</div>";
        if(knowledgeType == "DocumentKnowledge") {
            $("#playercontainerdiv").append(str);
        } else {
            $("#playercontainer").append(str);
        }
        if(knowledgeType == "VideoKnowledge") {
            if(typeof (myPlayer) != "undefined" && myPlayer.getState() == "playing") {
                myPlayer.pause();
            } else {
                clearInterval(timer);
                clearInterval(timecheck);
            }
        } else {
            clearInterval(timer);
            clearInterval(timecheck);
        }
    }
}

//追加已归档计划提醒
function AppendFilePlanHtml() {
    if($("#dvWarningView").length <= 0) {
        var str = "<div class='playgoon' id='divEditPlan'>" +
            "<div class='el-playgoon-shadow'></div>" +
            "<div class='playgoonbg'></div>" +
            "<div class='playgooncontent'>" + planfiled + "</div>" +
            "<input type='button' class='btnok' value='" + iknow + "' onclick='RemoveEditPlanHtml();' /></div>";
        //$("#playercontainer").before(str);
        if(knowledgeType == "DocumentKnowledge") {
            $("#playercontainerdiv").append(str);
        } else {
            $("#playercontainer").append(str);
        }
        if(knowledgeType == "VideoKnowledge") {
            if(typeof (myPlayer) != "undefined" && myPlayer.getState() == "playing") {
                myPlayer.pause();
            } else {
                clearInterval(timer);
            }
        } else {
            clearInterval(timer);
        }
    }
}

//追加修改计划中提醒
function AppendEditPlanHtml() {
    if($("#dvWarningView").length <= 0) {
        var str = "<div class='playgoon' id='divEditPlan'>" +
            "<div class='el-playgoon-shadow'></div>" +
            "<div class='playgoonbg'></div>" +
            "<div class='playgooncontent'>" + planupdated + "</div>" +
            "<input type='button' class='btnok' value='" + iknow + "' onclick='RemoveEditPlanHtml();' /></div>";
        if(knowledgeType == "DocumentKnowledge") {
            $("#playercontainerdiv").append(str);
        } else {
            $("#playercontainer").append(str);
        }
        if(knowledgeType == "VideoKnowledge") {
            if(typeof (myPlayer) != "undefined" && myPlayer.getState() == "playing") {
                myPlayer.pause();
            } else {
                clearInterval(timer);
            }
        } else {
            clearInterval(timer);
        }
    }
}
//删除修改计划中提醒
function RemoveEditPlanHtml() {
    $("#divEditPlan").remove();
    //显示学习提醒
    var isScorm = document.getElementById('iframeScorm');
    if(isScorm != null) {
        isScorm.style.display = '';
    }
    //    if (knowledgeType == "VideoKnowledge") {
    //        if (myPlayer.getState() == "paused") {
    //            myPlayer.play();
    //        } else {
    //            ResetTimer();
    //        }
    //    } else {
    //        ResetTimer();
    //    }
}

//同步进度
function SyncSchedule() {
    var masterTypeStr = masterType;
    if(masterType != "Plan" && masterType != "Position") {
        masterTypeStr = "";
    }
    var arr = '{"knowledgeId":"' + key + '","packageId":"' + packageID + '","masterId":"' + masterID + '","masterType":"' + masterTypeStr + '"}';
    AjaxCallApiMethod({
        type: "POST",
        url: "study/updateprogress",
        data: arr,
        cache: false,
        async: false,
        success: function (result) {
            result = eval("(" + result + ")");
            //            if (result.Status == "OK" && result.Data != "null") {
            //                result = eval("(" + result.Data + ")");
            actualStudyHours = result.actualstudyhours * 60;
            MinuteChange(result.studyschedule);
            //            }
        },
        error: function (xhr) {
        }
    });
}